
const hardWare = {
    namespaced: true,
    state: () => {
      return {
        spScanList: [], //五金仓入库
        returnSpScanList: [], //返回五金仓
        wjOutScanList: [],// 五金仓出库
        stockList:[],// 五金仓采购退料
        simpleList:[],// 简单生产退料
        iqcOutScanList:[],//质检其他出库
        iqcOutScanListOther:[]//质检其他出库
      }
    },
    mutations: {
      ADDSPSCANLIST: (state, params) => {
        // state.spScanList.push(params)
        if(state.spScanList.length == 0){
          let dict = {
            storeId:params.storeId,
            arr:[]
          }
          dict.arr.unshift(params)
          state.spScanList.push(dict)
        }else{
          // 用于筛选出相对应的storeId数组  如果有循环添加  如果没用保存新的
          let indexArr = state.spScanList.filter(x => x.storeId == params.storeId)
          if(indexArr.length == 0){
            let dict = {
              storeId:params.storeId,
              arr:[]
            }
            dict.arr.unshift(params)
            state.spScanList.push(dict)
          }else{
            state.spScanList.forEach(element => {
              if(element.storeId == params.storeId){
                element.arr.unshift(params)
              }
            });
          }
        }
      },
      DELSPSCANLISTITEM: (state, params) => {
        let spScanList = state.spScanList;
        spScanList[params.i].arr.splice(params.index,1)
      },
      // 删除已提交的数据
      REACTSPSUBMITTEDSCANLIST: (state,storeId) => {
        // state.spScanList = []
        console.log(storeId)
        state.spScanList.forEach((element,index) => {
          if(element.storeId == storeId){
            state.spScanList.splice(index,1)
          }
        });
      },
      /**
       * 返还五金仓 操作mutations
       * @param {*} context 
       * @param {*} params 
       */
      RETURNSPSCANLIST: (state, params) => {
        let arr = state.returnSpScanList.filter(x => x.barcode == params.barcode)
        if(arr.length == 0){
          state.returnSpScanList.unshift(params)
        }else{
          state.returnSpScanList.forEach(element => {
            if(element.barcode == params.barcode){
              element.inputNum = params.inputNum
            }
          });
        }
      },
      DELRETURNSPSCANLISTITEM: (state, params) => {
        console.log(params,'----params----')
        // 删除以后重新赋值 
        state.returnSpScanList.splice(params,1)
      },
      REACTRETURNSPSCANLIST: (state) => {
        state.returnSpScanList = []
      },
      /**
       * 五金仓出库 操作mutations
       * @param {*} context 
       * @param {*} params 
       */
       WJOUTSCANLIST: (state, params) => {
        let arr = state.wjOutScanList.filter(x => x.barcode == params.barcode)
        if(arr.length == 0){
          state.wjOutScanList.unshift(params)
        }else{
          state.wjOutScanList.forEach(element => {
            if(element.barcode == params.barcode){
              element.inputNum = params.inputNum
            }
          });
        }
      },
      DELWJOUTSCANLISTITEM: (state, params) => {
        // 删除以后重新赋值 
        state.wjOutScanList.splice(params,1)
      },
      REACTWJOUTSCANLIST: (state) => {
        state.wjOutScanList = []
      },
      /**
      * 其他出库 操作mutations
      * @param {*} context 
      * @param {*} params 
      */
      IQCOUTSCANLIST: (state, params) => {
        console.log(state.iqcOutScanList.filter(x => x.barcode == params.barcode))
        let arr = state.iqcOutScanList.filter(x => x.barcode == params.barcode)
        
        if (arr.length == 0) {
          state.iqcOutScanList.unshift(params)
        } else {
          state.iqcOutScanList.forEach(element => {
            if (element.barcode == params.barcode) {
              element.inputNum = params.inputNum
            }
          });
        }
      },
      DELIQCOUTSCANLISTITEM: (state, params) => {
        // 删除以后重新赋值 
        state.iqcOutScanList.splice(params, 1)
      },
      REACTIQCOUTSCANLIST: (state) => {
        state.iqcOutScanList = []
      },
       /**
      * 其他出库单 操作mutations
      * @param {*} context 
      * @param {*} params 
      */
       IQCOUTSCANLISTOTHER: (state, params) => {
        console.log(state.iqcOutScanListOther.filter(x => x.barcode == params.barcode))
        let arr = state.iqcOutScanListOther.filter(x => x.barcode == params.barcode)
        
        if (arr.length == 0) {
          state.iqcOutScanListOther.unshift(params)
        } else {
          state.iqcOutScanListOther.forEach(element => {
            if (element.barcode == params.barcode) {
              element.inputNum = params.inputNum
            }
          });
        }
      },
      DELIQCOUTSCANLISTITEMOTHER: (state, params) => {
        // 删除以后重新赋值 
        state.iqcOutScanListOther.splice(params, 1)
      },
      REACTIQCOUTSCANLISTOTHER: (state) => {
        state.iqcOutScanListOther = []
      },
      /**
       * 五金仓采购退料 操作mutations
       * @param {*} context 
       * @param {*} params 
       */
      STOCKLIST: (state, params) => {
        state.stockList.unshift(params)
      },
      DELSTOCKLISTITEM: (state, params) => {
        // 删除以后重新赋值 
        state.stockList.splice(params,1)
      },
      REACTSTOCKLIST: (state) => {
        state.stockList = []
      },
      // 简单生产退料
      SIMPLElIST: (state,params) => {
        state.simpleList.unshift(params)
      },
      DELSIMPLELISTITEM: (state,params) => {
        state.simpleList.splice(params,1)
      },
      REACTSIMPLELIST: (state) => {
        state.simpleList = []
      },
    },
    actions: {
      /**
       * 入库操作
       * @param {*} context 
       * @param {*} params 
       */
      setSpScanList(context, params) {
        context.commit('ADDSPSCANLIST', params) 
      },
      delSpScanListItem (context, params) {
        context.commit('DELSPSCANLISTITEM', params) 
      },
      resetSpSubmittedScanList (context,params) {
        context.commit('REACTSPSUBMITTEDSCANLIST',params) 
      },
      /**
       * 返还五金仓 操作actions
       * @param {*} context 
       * @param {*} params 
       */
      setReturnSpScanList (context, params) {
        context.commit('RETURNSPSCANLIST', params) 
      },
      delReturnSpScanListItem (context, params) {
        context.commit('DELRETURNSPSCANLISTITEM', params) 
      },
      resetReturnSpScanList (context) {
        context.commit('REACTRETURNSPSCANLIST') 
      },
      /**
       * 五金仓出库 操作actions
       * @param {*} context 
       * @param {*} params 
       */
      setWjOutScanList (context, params) {
        context.commit('WJOUTSCANLIST', params) 
      },
      delWjOutSpScanListItem (context, params) {
        context.commit('DELWJOUTSCANLISTITEM', params) 
      },
      resetWjOutScanList (context) {
        context.commit('REACTWJOUTSCANLIST') 
      },
      /**
       * 五金仓采购退料 操作actions
       * @param {*} context 
       * @param {*} params 
       */
      setStockList (context, params) {
        context.commit('STOCKLIST', params) 
      },
      delStockListItem (context, params) {
        context.commit('DELSTOCKLISTITEM', params) 
      },
      resetStockList (context) {
        context.commit('REACTSTOCKLIST') 
      },
      setSimpleScanList (context, params) {
        context.commit('SIMPLElIST', params) 
      },
      delSimpleListItem (context, params) {
        context.commit('DELSIMPLELISTITEM', params) 
      },
      resetSimpleList (context) {
        context.commit('REACTSIMPLELIST') 
      },
       /**
       * 其他出库 操作actions
       * @param {*} context 
       * @param {*} params 
       */
        setIqcOutScanList (context, params) {
          context.commit('IQCOUTSCANLIST', params) 
        },
        delIqcOutSpScanListItem (context, params) {
          context.commit('DELIQCOUTSCANLISTITEM', params) 
        },
        resetIqcOutScanList (context) {
          context.commit('REACTIQCOUTSCANLIST') 
        },
        /**
       * 其他出库单 操作actions
       * @param {*} context 
       * @param {*} params 
       */
        setIqcOutScanListOther (context, params) {
          context.commit('IQCOUTSCANLISTOTHER', params) 
        },
        delIqcOutSpScanListItemOther (context, params) {
          context.commit('DELIQCOUTSCANLISTITEMOTHER', params) 
        },
        resetIqcOutScanListOther (context) {
          context.commit('REACTIQCOUTSCANLISTOTHER') 
        },

    },
  };
  
  export default hardWare;
  
  